package com.lanchetech.user.controller;

import com.lanchetech.bean.request.PageReq;
import com.lanchetech.bean.response.BasePageResp;
import com.lanchetech.bean.response.BaseResp;
import com.lanchetech.bean.response.ResultData;
import com.lanchetech.bean.vo.*;
import com.lanchetech.entity.*;
import com.lanchetech.service.CommonFarmService;
import com.lanchetech.service.impl.CommonFarmServiceImpl;
import com.lanchetech.user.service.FarmService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@Api(value = "用户农场接口", tags = "用户农场接口")
@RequestMapping("/api/farm")
@RestController
public class FarmController {

    @Autowired
    FarmService farmService;

    @Autowired
    CommonFarmService commonFarmService;

    @ApiOperation(value = "获取公告信息分页")
    @PostMapping("/getMailBoxPage")
    public ResultData<BasePageResp<Mailbox>> getMailBoxPage(@RequestBody PageReq req) {
        return farmService.getMailBoxPage(req);
    }

    @ApiOperation(value = "获取兑换商品分页")
    @PostMapping("/getFarmProductPage")
    public ResultData<BasePageResp<FarmProduct>> getFarmProductPage(@RequestBody PageReq req) {
        return farmService.getFarmProductPage(req);
    }

    @ApiOperation(value = "兑换牧场商品")
    @PostMapping("/exchangeFarmProduct")
    public BaseResp exchangeFarmProduct(@RequestBody FarmOrder farmOrder) {
        return farmService.exchangeFarmProduct(farmOrder);
    }

    @ApiOperation(value = "兑换果园商品")
    @PostMapping("/exchangeTreeProduct")
    public BaseResp exchangeTreeProduct(@RequestBody FarmOrder farmOrder) {
        return farmService.exchangeTreeProduct(farmOrder);
    }

    @ApiOperation(value = "我的兑换商品")
    @PostMapping("/getMyExchangeProductPage")
    public ResultData<BasePageResp<FarmOrderVO>> getMyExchangeProductPage(@RequestBody PageReq req) {
        return farmService.getMyExchangeProductPage(req);
    }

    @ApiOperation(value = "获取草料流水分页")
    @PostMapping("/getGrassFlowPage")
    public ResultData<BasePageResp<GrassFlowVO>> getGrassFlowPage(@RequestBody PageReq req) {
        return farmService.getGrassFlowPage(req);
    }

    @ApiOperation(value = "获取水能量流水分页")
    @PostMapping("/getWaterFlowPage")
    public ResultData<BasePageResp<WaterFlowVO>> getWaterFlowPage(@RequestBody PageReq req) {
        return farmService.getWaterFlowPage(req);
    }

    @ApiOperation(value = "获取牧场详情")
    @GetMapping("/getCowDetail")
    public ResultData<FarmUserVO> getCowDetail(@AuthenticationPrincipal User user) {
        return farmService.getCowDetail(user);
    }

    @ApiOperation(value = "编辑奶牛")
    @PostMapping("/editCow")
    public BaseResp editCow(@RequestBody Cow cow) {
        return farmService.editCow(cow);
    }

    @ApiOperation(value = "奶牛吃草")
    @GetMapping("/eatGrass")
    public BaseResp eatGrass(@RequestParam("grass") BigDecimal grass) {
        return farmService.eatGrass(grass);
    }

    @ApiOperation(value = "奶牛挤奶")
    @GetMapping("/milking")
    public BaseResp milking(@AuthenticationPrincipal User user) {
        return farmService.milking(user);
    }

    @ApiOperation(value = "获取累计排行")
    @GetMapping("/getCowRank")
    public ResultData<List<FarmUserRankVO>> getCowRank(@AuthenticationPrincipal User user) {
        return farmService.getCowRank(user);
    }

    @ApiOperation(value = "获取果园详情")
    @GetMapping("/getTreeDetail")
    public ResultData<FarmUserVO> getTreeDetail(@AuthenticationPrincipal User user) {
        return farmService.getTreeDetail(user);
    }

    @ApiOperation(value = "获取当前果树详情")
    @GetMapping("/getCurrentTreeDetail")
    public ResultData<TreeVO> getCurrentTreeDetail() {
        return farmService.getCurrentTreeDetail();
    }

    @ApiOperation(value = "改变树选择")
    @GetMapping("/editTreeIsActive")
    public BaseResp editTreeIsActive(@RequestParam("treeId") Long treeId) {
        return farmService.editTreeIsActive(treeId);
    }

    @ApiOperation(value = "种果树")
    @GetMapping("/addTree")
    public BaseResp addTree(@AuthenticationPrincipal User user, @RequestParam("saplingId") Long saplingId) {
        return farmService.addTree(user, saplingId);
    }

    @ApiOperation(value = "放弃果树")
    @GetMapping("/giveUpTree")
    public BaseResp giveUpTree(@RequestParam("treeId") Long treeId) {
        return farmService.giveUpTree(treeId);
    }

    @ApiOperation(value = "获取树苗列表")
    @GetMapping("/getSaplingList")
    public ResultData<List<Sapling>> getSaplingList(@AuthenticationPrincipal User user) {
        return farmService.getSaplingList(user);
    }

    @ApiOperation(value = "树苗浇水")
    @GetMapping("/waterTree")
    public BaseResp waterTree(@RequestParam("treeId") Long treeId, @RequestParam("water") BigDecimal water) {
        return farmService.waterTree(treeId, water);
    }

    @ApiOperation(value = "获取果园排行榜")
    @GetMapping("/getTreeRank")
    public ResultData<List<FarmUserRankVO>> getTreeRank(@AuthenticationPrincipal User user) {
        return farmService.getTreeRank(user);
    }

    @ApiOperation(value = "施肥")
    @GetMapping("/applyFertilizer")
    public BaseResp applyFertilizer(@AuthenticationPrincipal User user, @RequestParam("fertilizer") BigDecimal fertilizer, @RequestParam("treeId") Long treeId) {
        return farmService.applyFertilizer(user, fertilizer, treeId);
    }

    @ApiOperation(value = "查看农场任务分页")
    @PostMapping("/getFarmTaskPage")
    public ResultData<BasePageResp<FarmTaskVO>> getFarmTaskPage(@RequestBody PageReq req) {
        return farmService.getFarmTaskPage(req);
    }

    @ApiOperation(value = "领取任务")
    @PostMapping("/editUserTask")
    public BaseResp editUserTask(@RequestBody UserTask userTask) {
        return farmService.editUserTask(userTask);
    }

    @ApiOperation(value = "执行农场任务")
    @GetMapping("/doneUserTask")
    public ResultData<Boolean> doneUserTask(@AuthenticationPrincipal User user, @RequestParam("kind") Long kind, @RequestParam(value = "relateId", required = false) Long relateId, @RequestParam(value = "count", required = false) Long count) {
        return new ResultData<>(commonFarmService.checkTaskDone(user, kind, relateId, count));
    }



}
